import { computed } from "vue";
import { useDark } from "@pureadmin/utils";
import { NewsStatus } from "./utils/types";

export function useNewsHook() {
  const { isDark } = useDark();

  const switchStyle = computed(() => {
    return {
      "--el-switch-on-color": "#13ce66",
      "--el-switch-off-color": "#ff4949"
    };
  });

  const tagStyle = computed(() => {
    return (status: number) => {
      return {
        "--el-tag-text-color": isDark.value ? "#fff" : "#000",
        "--el-tag-bg-color": isDark.value
          ? getStatusDarkColor(status)
          : getStatusLightColor(status),
        "--el-tag-border-color": isDark.value
          ? getStatusDarkColor(status)
          : getStatusLightColor(status)
      };
    };
  });

  const getStatusColor = (status: number) => {
    switch (status) {
      case NewsStatus.DRAFT:
        return "#909399";
      case NewsStatus.PUBLISHED:
        return "#67c23a";
      case NewsStatus.OFFLINE:
        return "#f56c6c";
      default:
        return "#909399";
    }
  };

  const getStatusLightColor = (status: number) => {
    switch (status) {
      case NewsStatus.DRAFT:
        return "#f4f4f5";
      case NewsStatus.PUBLISHED:
        return "#f0f9ff";
      case NewsStatus.OFFLINE:
        return "#fef0f0";
      default:
        return "#f4f4f5";
    }
  };

  const getStatusDarkColor = (status: number) => {
    switch (status) {
      case NewsStatus.DRAFT:
        return "#262727";
      case NewsStatus.PUBLISHED:
        return "#1f2937";
      case NewsStatus.OFFLINE:
        return "#2d1b1b";
      default:
        return "#262727";
    }
  };

  const getStatusTagType = (status: number) => {
    switch (status) {
      case NewsStatus.DRAFT:
        return "info";
      case NewsStatus.PUBLISHED:
        return "success";
      case NewsStatus.OFFLINE:
        return "danger";
      default:
        return "info";
    }
  };

  const getPriorityTagType = (isTop: boolean, isRecommend: boolean) => {
    if (isTop) return "danger";
    if (isRecommend) return "warning";
    return "";
  };

  const getPriorityText = (isTop: boolean, isRecommend: boolean) => {
    if (isTop) return "置顶";
    if (isRecommend) return "推荐";
    return "";
  };

  return {
    switchStyle,
    tagStyle,
    getStatusColor,
    getStatusTagType,
    getPriorityTagType,
    getPriorityText
  };
}